<?php
// +----------------------------------------------
// | Created by PhpStorm
// +----------------------------------------------
// | Author: YnnSon
// +----------------------------------------------
namespace app\lib\exception;

use think\Exception;

/**
 * 自定义异常类的基类
 * Class BaseException
 * @package app\lib\exception
 */
class BaseException extends Exception
{
    public $code = 400;
    public $message = '未知错误';
    public $errorCode = 10000;

    /**
     * @desc 构造函数，接收一个关联数组
     *
     * @param array $param 关联数组只应包含code、message和errorCode，且不应该是空值
     */
    public function __construct($param = [])
    {
        if (!is_array($param)) {
            return;
        }
        if (array_key_exists('result', $param)) {
            $this->result = $param['result'];
        }
        if (array_key_exists('code', $param)) {
            $this->code = $param['code'];
        }
        if (array_key_exists('message', $param)) {
            $this->message = $param['message'];
        }
        if (array_key_exists('errorCode', $param)) {
            $this->errorCode = $param['errorCode'];
        }
    }
}